package com.fp.m7.shared.validator;

import org.springframework.stereotype.Component;

import com.fp.m7.shared.ValidationConstants;
import com.fp.m7.shared.ValidationError;
import com.fp.m7.shared.ValidationResult;

@Component
public class NewPasswordsValidator {

    public ValidationResult validate(String newPwd, String newPwdRpt) {
        ValidationResult result = new ValidationResult();

        if (newPwd == null || !newPwd.matches(ValidationConstants.PASSWORD_REGEX)) {
            result.add(new ValidationError(ValidationConstants.Fields.NEW_PASSWORD,
                    ValidationConstants.Messages.REGEX_FAIL));
        } else if (newPwdRpt == null || !newPwd.equals(newPwdRpt)) {
            result.add(new ValidationError(ValidationConstants.Fields.NEW_PASSWORD_REPEATED,
                    ValidationConstants.Messages.NO_MATCH));
        }

        return result;
    }

}
